from django import http
from django.shortcuts import render

# Create your views here.
from django.views import View
from django_redis import get_redis_connection

from meiduo_mall.libs.captcha.captcha import captcha


class ImageCodeView(View):
    def get(self, request, uuid):
        # 1.生成图片验证码
        text, image = captcha.generate_captcha()
        # 2.连接数据库
        redis_conn = get_redis_connection('verify_code')
        # 3.将验证码存进redis
        key = 'img_%s' % uuid
        redis_conn.setex(key, 300, text)
        # 4.return
        return http.HttpResponse(image, content_type='image/jpg')


